/*const o = {a:1,b:2}
Object.defineProperty(o,'a',{
  get(){
    console.log('get');
    return o.a
  },
  set(v) {
    console.log('set');
    if(v===o.a) return;
    o.a = 123
  }
})

o.a = 1*/

/*
get
get
get
get
internal/console/constructor.js:280
        if (isStackOverflowError(e))
            ^

RangeError: Maximum call stack size exceeded
* */

const o = {a:1,b:2}

function defineReactive(data,key,value){
  Object.defineProperty(data,key,{
    get(){
      console.log('get');
      return value
    },
    set(v) {
      console.log('set');
      console.log('value:',value);
      if(v === value) return;
      value = v
    }
  })
  //↑ 这么一定义以后, 不论查找还是设置 操作的都是这个闭包里的value 和o.a原本的值没有关系了
}

defineReactive(o,'a',1)
console.log('console.log(o.a)~~~~~~~~~~~~~~~~~~~~~~~~~');
console.log(o.a);
//get
// 1
console.log('o.a = 123~~~~~~~~~~~~~~~~~~~~~~~~~');
o.a = 123
// set
// value: 1
console.log('o.a~~~~~~~~~~~~~~~~~~~~~~~~~');
console.log(o.a);
// get
// 123
console.log('o.a = 234~~~~~~~~~~~~~~~~~~~~~~~~~');
o.a = 234
// set
// value: 123
console.log('o.a~~~~~~~~~~~~~~~~~~~~~~~~~');
console.log(o.a);
// get
// 234
console.dir(o) //{ a: [Getter/Setter], b: 2 }
